﻿
CREATE FUNCTION dbo.credit_1234s
	(
	@PaymentPattern varchar(512),
	@DateStart smalldatetime = '1/1/2000'
	)
RETURNS @T TABLE (RatingCode int, Date smalldatetime)
AS
BEGIN

DECLARE @Code char(1)

WHILE @PaymentPattern > '' BEGIN

	SET @Code = SUBSTRING(@PaymentPattern,1,1)

	IF ISNUMERIC(@Code) = 1
		INSERT INTO @T VALUES(@Code,@DateStart)

	SET @DateStart = DATEADD(mm,-1,@DateStart)
	SET @PaymentPattern = SUBSTRING(@PaymentPattern,2,1000)

END

RETURN

END

